
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    
<div class="archive_info">
<h1>JavaScript <span class="color_h1">注释</span>
</h1>
<hr/>
<p class="intro">JavaScript 注释可用于提高代码的可读性。</p>
<hr/>
<h2>JavaScript 注释</h2>
<p>JavaScript 不会执行注释。</p>
<p>我们可以添加注释来对 JavaScript 进行解释，或者提高代码的可读性。</p>
<p>单行注释以 <span class="marked">//</span> 开头。</p>
<p>本例用单行注释来解释代码：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-comment">//</span><span class="hl-comment"> 输出标题：</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">myH1</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">innerHTML</span><span class="hl-code">=</span><span class="hl-quotes">"</span><span class="hl-string">欢迎来到我的主页</span><span class="hl-quotes">"</span><span class="hl-code">;
</span><span class="hl-comment">//</span><span class="hl-comment"> 输出段落：</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">myP</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">innerHTML</span><span class="hl-code">=</span><span class="hl-quotes">"</span><span class="hl-string">这是我的第一个段落。</span><span class="hl-quotes">"</span><span class="hl-code">;</span></div>
</div>
<br/><a class="tryitbtn"  target="_blank">尝试一下 »</a>
</div>
<br/><hr/>
<h2>JavaScript 多行注释</h2>
<p>多行注释以 <span class="marked">/*</span> 开始，以 <span class="marked">*/</span> 结尾。
</p>
<p>下面的例子使用多行注释来解释代码：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-comment">/*</span><span class="hl-comment">
下面的这些代码会输出
一个标题和一个段落
并将代表主页的开始
</span><span class="hl-comment">*/</span><span class="hl-code">
</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">myH1</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">innerHTML</span><span class="hl-code">=</span><span class="hl-quotes">"</span><span class="hl-string">欢迎来到我的主页</span><span class="hl-quotes">"</span><span class="hl-code">;
</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">myP</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">innerHTML</span><span class="hl-code">=</span><span class="hl-quotes">"</span><span class="hl-string">这是我的第一个段落。</span><span class="hl-quotes">"</span><span class="hl-code">;</span></div>
</div>
<br/><a class="tryitbtn"  target="_blank">尝试一下 »</a>
</div>
<br/><hr/>
<h2>使用注释来阻止执行</h2>
<p>在下面的例子中，注释用于阻止其中一条代码行的执行（可用于调试）：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code"><div class="hl-main"><span class="hl-comment">//</span><span class="hl-comment"> document.getElementById("myH1").innerHTML="欢迎来到我的主页";</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-builtin">document</span><span class="hl-code">.</span><span class="hl-identifier">getElementById</span><span class="hl-brackets">(</span><span class="hl-quotes">"</span><span class="hl-string">myP</span><span class="hl-quotes">"</span><span class="hl-brackets">)</span><span class="hl-code">.</span><span class="hl-identifier">innerHTML</span><span class="hl-code">=</span><span class="hl-quotes">"</span><span class="hl-string">这是我的第一个段落。</span><span class="hl-quotes">"</span><span class="hl-code">;</span></div>
</div>
<br/><a class="tryitbtn"  target="_blank">尝试一下 »</a>
</div>
<p>在下面的例子中，注释用于阻止代码块的执行（可用于调试）：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-comment">/*</span><span class="hl-comment">
document.getElementById("myH1").innerHTML="欢迎来到我的主页";
document.getElementById("myP").innerHTML="这是我的第一个段落。";
</span><span class="hl-comment">*/</span></div>
</div>
<br/><a class="tryitbtn"  target="_blank">尝试一下 »</a>
</div>
<br/><hr/>
<h2>在行末使用注释</h2>
<p>在下面的例子中，我们把注释放到代码行的结尾处：</p>
<div class="example">
<h2 class="example">实例</h2>
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">var</span><span class="hl-code"> </span><span class="hl-identifier">x</span><span class="hl-code">=</span><span class="hl-number">5</span><span class="hl-code">;    </span><span class="hl-comment">//</span><span class="hl-comment"> 声明 x 并把 5 赋值给它</span><span class="hl-comment"></span><span class="hl-code">
</span><span class="hl-reserved">var</span><span class="hl-code"> </span><span class="hl-identifier">y</span><span class="hl-code">=</span><span class="hl-identifier">x</span><span class="hl-code">+</span><span class="hl-number">2</span><span class="hl-code">;  </span><span class="hl-comment">//</span><span class="hl-comment"> 声明 y 并把 x+2 赋值给它</span><span class="hl-comment"></span></div>
</div>
<br/><a class="tryitbtn"  target="_blank">尝试一下 »</a>
</div> <div class="scroll-top"><a >返回顶部</a></div>
</div>

    </body>
    </html>
    